package gui;

import javax.swing.*;
import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 * User: kate
 * Date: 07.06.2009
 * Time: 15:59:08
 * To change this template use File | Settings | File Templates.
 */
public class BackgroundPanel extends JPanel {
    Image image;

    public BackgroundPanel(String url) {
        try {
            image = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource(url), url));
        }
        catch (Exception e) { /*handled in paintComponent()*/ }
    }

    public void setNewImage(String url) {
        try {
            image = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource(url), url));
        }
        catch (Exception e) { /*handled in paintComponent()*/ }

    }

    @Override
    protected void paintComponent(Graphics g) {
        this.setSize(900, 675);
        this.setLocation(0, 0);
        Point p = getLocation();
        //System.out.println("BackgroundComp->height:" + this.getHeight() + "; width:" +this.getWidth() + "x:"+p.x + "; y=" + p.y);
        super.paintComponent(g);
        if (image != null)
            g.drawImage(image, 0, 0, 900, 675, this);
        byte byt = 0;
    }
}
